package lumis.portal.serialization.operation;

/**
 * Represents a foreign key (field) of a portal object 
 *
 * @version $Revision: 5769 $ $Date: 2007-02-01 12:00:07 -0200 (Thu, 01 Feb 2007) $
 * @since 4.0.9
 */
public class ConfigForeignKey
{
	private final String name;
	private final String violationValue;
	private final boolean persistIfViolated;
	private final boolean abortIfViolated;
	private final boolean mutable;
	private final IConfigKeyChecker checker;
	/**
	 * Constructs a ConfigForeignKey that references an object that could not be already persisted and, in this case, has to be analyzed. 
	 * @param name Config field name
	 * @param violationValue If the original value represents a violated foreign key, this value will be used to generate a persistable Config object.  
	 * @param persistIfViolated The generated persistable Config object can be persisted, if the original value represents a violated foreign key.   
	 * @param abortIfViolated The deserialization process must be aborted at the end, if the original value represents a violated foreign key.
	 * @param mutable The field can be mapped to a new value. e.g. channelId is a mutable value, while a serviceId is not mutable.
	 * @param checker {@link IConfigKeyChecker} implementation that checks if the foreign key value is violated.
	 */
	public ConfigForeignKey(final String name, final String violationValue, final boolean persistIfViolated, final boolean abortIfViolated, final boolean mutable, final IConfigKeyChecker checker)
	{
		super();
		this.name = name;
		this.violationValue = violationValue;
		this.persistIfViolated = persistIfViolated;
		this.abortIfViolated = abortIfViolated;
		this.mutable = mutable;
		this.checker = checker;
	}
	/**
	 * Constructs a ConfigForeignKey that references an object that has certainly already persisted and, in this case, does not have to be analyzed. 
	 * @param name Config field name
	 */
	public ConfigForeignKey(final String name)
	{
		super();
		this.name = name;
		this.violationValue = null;
		this.persistIfViolated = false;
		this.abortIfViolated = false;
		this.mutable = true;
		this.checker = null;
	}

	public boolean getAbortIfViolated()
	{
		return abortIfViolated;
	}
	public IConfigKeyChecker getChecker()
	{
		return checker;
	}
	public String getName()
	{
		return name;
	}
	public boolean getPersistIfViolated()
	{
		return persistIfViolated;
	}
	public boolean isMutable()
	{
		return mutable;
	}
	public String getViolationValue()
	{
		return violationValue;
	}
	@Override
	public String toString()
	{
		return "name:" + name + 
		" violationValue:" + (violationValue == null ? "null" : violationValue) +
		" persistIfViolated:" + Boolean.toString(persistIfViolated) +
		" abortIfViolated:" + Boolean.toString(abortIfViolated) + 
		" mutable:" + Boolean.toString(mutable) +
		" checker:" + (checker == null ? "null" : checker.getClass().getName());
	}
	
}